/*---------------------------------------------------------------------------
	ZaRan	-	A Totallly Automatic CFD Software
	Copyright (C) ,Since 2020
-------------------------------------------------------------------------------
License
	This file is part of ZaRan.

!	@file		gird.h
!	@brief	the purpose of this file.
!	@author	Chen Jie.
\*---------------------------------------------------------------------------*/
#include"model/include/model.h"
void Mod::AddMod(vector<ModBase*> modVec)
{
	for (int iModel = 0; iModel < modVec.size(); ++iModel)
		AddMod(modVec[iModel]);
}
void Mod::AddMod(Mod* mod)
{
	for (int iModel = 0; iModel < mod->modelVec.size(); ++iModel)
		AddMod(mod->modelVec[iModel]);
}

bool Mod::IsInModel(const Point& pt)
{
	bool inMod = false;
	for (int iModel = 0; iModel < modelVec.size(); ++iModel)
	{
		inMod = inMod || modelVec[iModel]->IsInModel(pt);
	}
	return inMod;
}

void Mod::GetPointCloud(const double delta)
{
	for (int iModel = 0; iModel < modelVec.size(); ++iModel)
	{
		modelVec[iModel]->GenModelPoint(delta);
	}
}

Point Mod::GetClosestPoint(const Point& pt)
{
	Point NearPt = modelVec[0]->GetClosestPoint(pt);
	double min_dist = distance(NearPt, pt);
	Point TmpPt;
	if (modelVec.size() > 0)
	{
		for (int iModel = 1; iModel < modelVec.size(); ++iModel)
		{
			TmpPt = modelVec[iModel]->GetClosestPoint(pt);
			if (distance(TmpPt, pt) < min_dist)
			{
				min_dist = distance(TmpPt, pt);
				NearPt = TmpPt;
			}
		}
	}
	return NearPt;
}

double Mod::NearestDistance(const Point& pt)
{
	double minDistance = modelVec[0]->NearestDistance(pt);
	double tmpDis;
	if (modelVec.size() > 0)
	{
		for (int iModel = 1; iModel < modelVec.size(); ++iModel)
		{
			minDistance = std::min(minDistance, modelVec[iModel]->NearestDistance(pt));
		}
	}
	return minDistance;
}
